package org.babygo.connect.util;

import java.net.SocketAddress;
import java.util.Random;

public class CommonUtil {

	public static String[] getIpAndPort(SocketAddress address){
		String[] ipAndPort = new String[2];
		ipAndPort[0] = address.toString().split(":")[0].substring(1);
		ipAndPort[1] = address.toString().split(":")[1];
		return ipAndPort;
	}

	public static String getFixLenthString(int strLength) {
		Random rm = new Random();
		// 获得随机数
		double pross = (1 + rm.nextDouble()) * Math.pow(10, strLength);
		// 将获得的获得随机数转化为字符串
		String fixLenthString = String.valueOf(pross);
		// 返回固定的长度的随机数
		return fixLenthString.substring(1, strLength + 1);
	}
}